﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jiuyong
{
	public class Subcommand<T>
	{
		public string Name;
		public Action<T> Callback;
		public Func<T> GetDefault;
		public string Message;
		public Func<IEnumerable<T>> GetOthers;
	}
	public class SubcommandCollection<T> : System.Collections.ObjectModel.KeyedCollection<string, Subcommand<T>>
	{
		protected override string GetKeyForItem(Subcommand<T> item)
		{
			return item.Name;
		}

		public void Add(string name, Action<T> callback = null, Func<T> getDefaultText = null, string dialogMessage = null, Func<IEnumerable<T>> getOtherTexts = null)
		{
			var r = new Subcommand<T>();
			r.Name = name;
			r.Callback = callback;
			r.GetDefault = getDefaultText;
			r.Message = dialogMessage;
			r.GetOthers = getOtherTexts;
			Add(r);
		}
	}
}
